package engine;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import java.awt.*;
import java.io.File;

public class musicStuff {
    Clip playMusic(String musicLocation) {
        try {
            File musicPath = new File(musicLocation);

            if(musicPath.exists()) {
                AudioInputStream audioInput = AudioSystem.getAudioInputStream(musicPath);
                Clip clip = AudioSystem.getClip();
                clip.open(audioInput);
                clip.start();

                return clip;
            }
            else{
                return null;
            }
        }
        catch(Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    void stopMusic(String musicLocation) throws LineUnavailableException {

                //AudioInputStream audioInput = AudioSystem.getAudioInputStream(musicPath);
                Clip clip = AudioSystem.getClip();
                //clip.open(audioInput);
                clip.stop();

    }

}